<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="laravel-包开发" tabindex="-1"><a class="header-anchor" href="#laravel-包开发"><span>Laravel 包开发</span></a></h2>
<ul>
<li><a href="#introduction">介绍</a>
<ul>
<li><a href="#a-note-on-facades">关于 Facades 的说明</a></li>
</ul>
</li>
<li><a href="#package-discovery">包发现</a></li>
<li><a href="#service-providers">服务提供者</a></li>
<li><a href="#resources">资源</a>
<ul>
<li><a href="#configuration">配置</a></li>
<li><a href="#migrations">迁移</a></li>
<li><a href="#routes">路由</a></li>
<li><a href="#language-files">语言文件</a></li>
<li><a href="#views">视图</a></li>
<li><a href="#view-components">视图组件</a></li>
<li><a href="#about-artisan-command">「About」Artisan 命令</a></li>
</ul>
</li>
<li><a href="#commands">命令</a></li>
<li><a href="#public-assets">前端公共资源</a></li>
<li><a href="#publishing-file-groups">发布文件组</a></li>
</ul>
<h2 id="介绍" tabindex="-1"><a class="header-anchor" href="#介绍"><span>介绍</span></a></h2>
<p>包是向 Laravel 添加功能的主要方式。包可以是任何东西，从处理日期的好方法例如 <a href="https://github.com/briannesbitt/Carbon" target="_blank" rel="noopener noreferrer">Carbon</a>，到允许你将文件与 Eloquent 模型关联的包，比如 Spatie 的 <a href="https://github.com/spatie/laravel-medialibrary" target="_blank" rel="noopener noreferrer">Laravel Media Library</a>。</p>
<p>有不同类型的包。有些包是独立的，意味着它们适用于任何 PHP 框架。Carbon 和 Pest 就是独立包的例子。这些包通过在 <code v-pre>composer.json</code> 文件中要求它们，可以被用于 Laravel。</p>
<p>另一方面，有些包是专门为 Laravel 使用而设计的。这些包可能有专门旨在增强 Laravel 应用程序的路由、控制器、视图和配置。本指南主要涵盖那些特定于 Laravel 的包的开发。</p>
<h3 id="关于-facades-的说明" tabindex="-1"><a class="header-anchor" href="#关于-facades-的说明"><span>关于 Facades 的说明</span></a></h3>
<p>当编写 Laravel 应用程序时，通常不重要你是使用 contracts 还是 facades，因为两者都提供基本相等的可测试性级别。然而，当编写包时，你的包通常无法访问 Laravel 的所有测试助手。如果你想能够编写测试，就像包是安装在典型的 Laravel 应用程序中一样，你可以使用 <a href="https://github.com/orchestral/testbench" target="_blank" rel="noopener noreferrer">Orchestral Testbench</a> 包。</p>
<h2 id="包发现" tabindex="-1"><a class="header-anchor" href="#包发现"><span>包发现</span></a></h2>
<p>Laravel 应用的 <code v-pre>bootstrap/providers.php</code> 文件包含了 Laravel 应该加载的服务提供者列表。你可以在包的 <code v-pre>composer.json</code> 文件的 <code v-pre>extra</code> 区域定义提供者，使之可以由 Laravel 自动加载，而不用手动将其添加到服务提供者列表中。除了服务提供者外，你还可以列出你想注册的任何<a href="https://learnku.com/docs/laravel/11.x/facadesmd" target="_blank" rel="noopener noreferrer">门面</a>：</p>
<div class="language-json line-numbers-mode" data-highlighter="prismjs" data-ext="json" data-title="json"><pre v-pre class="language-json"><code><span class="line"><span class="token property">"extra"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token property">"laravel"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token property">"providers"</span><span class="token operator">:</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string">"Barryvdh\\Debugbar\\ServiceProvider"</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token property">"aliases"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token property">"Debugbar"</span><span class="token operator">:</span> <span class="token string">"Barryvdh\\Debugbar\\Facade"</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>当你的包配置了包发现后，Laravel 会在安装该包时自动注册服务提供者及 Facades，这样就为你的包用户创造一个便利的安装体验。</p>
<h4 id="退出包发现" tabindex="-1"><a class="header-anchor" href="#退出包发现"><span>退出包发现</span></a></h4>
<p>如果你是包消费者，要禁用包发现功能，你可以在应用的 <code v-pre>composer.json</code> 文件的 <code v-pre>extra</code> 区域列出包名：</p>
<div class="language-json line-numbers-mode" data-highlighter="prismjs" data-ext="json" data-title="json"><pre v-pre class="language-json"><code><span class="line"><span class="token property">"extra"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token property">"laravel"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token property">"dont-discover"</span><span class="token operator">:</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string">"barryvdh/laravel-debugbar"</span></span>
<span class="line">        <span class="token punctuation">]</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>你可以在应用的 <code v-pre>dont-discover</code> 指令中使用 <code v-pre>*</code> 字符，禁用所有包的包发现功能：</p>
<div class="language-json line-numbers-mode" data-highlighter="prismjs" data-ext="json" data-title="json"><pre v-pre class="language-json"><code><span class="line"><span class="token property">"extra"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token property">"laravel"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token property">"dont-discover"</span><span class="token operator">:</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string">"*"</span></span>
<span class="line">        <span class="token punctuation">]</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="服务提供者" tabindex="-1"><a class="header-anchor" href="#服务提供者"><span>服务提供者</span></a></h2>
<p><a href="https://learnku.com/docs/laravel/11.x/providersmd/16655" target="_blank" rel="noopener noreferrer">服务提供者</a>是你的包和 Laravel 之间的连接点。服务提供者负责将服务绑定到 Laravel 的服务容器并告知 Laravel 到哪里去加载包资源，比如视图、配置及语言文件。</p>
<p>服务提供者继承了 <code v-pre>Illuminate/Support/ServiceProvider</code> 类，包含两个方法： <code v-pre>register</code> 和 <code v-pre>boot</code>。基础的 <code v-pre>ServiceProvider</code> 类位于 <code v-pre>illuminate/support</code> Composer 包中，你应该把它添加到你自己包的依赖项中。要了解更多关于服务提供者的结构和目的，请查看<a href="https://learnku.com/docs/laravel/11.x/providersmd/16655" target="_blank" rel="noopener noreferrer">服务提供者文档</a>.</p>
<h2 id="资源" tabindex="-1"><a class="header-anchor" href="#资源"><span>资源</span></a></h2>
<h3 id="配置" tabindex="-1"><a class="header-anchor" href="#配置"><span>配置</span></a></h3>
<p>通常情况下，你需要将包的配置文件发布到应用程序的 <code v-pre>config</code> 目录下。这将允许在使用包时覆盖扩展包中的默认配置选项。要允许发布配置文件，需要在服务提供者的 <code v-pre>boot</code> 方法中调用 <code v-pre>publishes</code> 方法:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Bootstrap any package services.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">publishes</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">        <span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../config/courier.php'</span> <span class="token operator">=></span> <span class="token function">config_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'courier.php'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>现在，当包用户执行 Laravel 的 <code v-pre>vendor:publish</code> 命令时，配置文件将被复制到指定的发布位置。当配置发布后，它的值可以像其他的配置文件一样被访问:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$value</span> <span class="token operator">=</span> <span class="token function">config</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'courier.option'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><blockquote>
<p><strong>警告</strong><br>
你不应该在你的配置文件中定义闭包。当用户执行 <code v-pre>config:cache</code> Artisan 命令时，它们不能被正确序列化。</p>
</blockquote>
<h4 id="默认的包配置" tabindex="-1"><a class="header-anchor" href="#默认的包配置"><span>默认的包配置</span></a></h4>
<p>你也可以将你自己的包的配置文件与应用程序的发布副本合并。这将允许你的用户在配置文件的发布副本中只定义他们真正想要覆盖的选项。要合并配置文件的值，请在你的服务提供者的 <code v-pre>register</code> 方法中使用 <code v-pre>mergeConfigFrom</code> 方法。</p>
<p><code v-pre>mergeConfigFrom</code> 方法的第一个参数是你的包的配置文件的路径，第二个参数是应用程序的配置文件副本的名称：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Register any application services.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">mergeConfigFrom</span><span class="token punctuation">(</span></span>
<span class="line">        <span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../config/courier.php'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'courier'</span></span>
<span class="line">    <span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p><strong>警告</strong><br>
这个方法只合并了配置数组的第一层。如果你的用户部分地定义了一个多维的配置数组，缺少的选项将不会被合并。</p>
</blockquote>
<h3 id="路由" tabindex="-1"><a class="header-anchor" href="#路由"><span>路由</span></a></h3>
<p>如果你的软件包包含路由，你可以使用 <code v-pre>loadRoutesFrom</code> 方法加载它们。这个方法会自动判断应用程序的路由是否被缓存，如果路由已经被缓存，则不会加载你的路由文件：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导包服务.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">loadRoutesFrom</span><span class="token punctuation">(</span><span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../routes/web.php'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="迁移" tabindex="-1"><a class="header-anchor" href="#迁移"><span>迁移</span></a></h3>
<p>如果你的包包含 <a href="https://learnku.com/docs/laravel/11.x/migrationsmd/16699" target="_blank" rel="noopener noreferrer">数据库迁移</a>，可以使用 <code v-pre>publishesMigrations</code> 方法通知 Laravel 给定的目录或文件包含迁移。当 Laravel 发布这些迁移时，它将自动更新其文件名中的时间戳以反映当前的日期和时间：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导包服务.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">publishesMigrations</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">        <span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../database/migrations'</span> <span class="token operator">=></span> <span class="token function">database_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'migrations'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="语言文件" tabindex="-1"><a class="header-anchor" href="#语言文件"><span>语言文件</span></a></h3>
<p>如果你的包包含 <a href="https://learnku.com/docs/laravel/11.x/localization/14868" target="_blank" rel="noopener noreferrer">语言文件</a>，可以使用 <code v-pre>loadTranslationsFrom</code> 方法告知 Laravel 如何加载它们。例如，如果您的包名为 <code v-pre>courier</code>, 您应在服务提供者的 <code v-pre>boot</code> 方法中添加以下内容：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导包服务.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">loadTranslationsFrom</span><span class="token punctuation">(</span><span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../lang'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'courier'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>包翻译行使用 <code v-pre>package::file.line</code> 语法约定引用。因此，一旦您的视图路径在服务提供者中注册，您就可以这样加载 <code v-pre>courier</code> 包的<code v-pre>messages</code>文件中的 <code v-pre>welcome</code> 行 :</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">echo</span> <span class="token function">trans</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'courier::messages.welcome'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>您可以使用 <code v-pre>loadJsonTranslationsFrom</code> 方法为您的包注册 JSON 翻译文件。此方法接受包含包的 JSON 翻译文件目录的路径：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导包服务.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">loadJsonTranslationsFrom</span><span class="token punctuation">(</span><span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../lang'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="发布语言文件" tabindex="-1"><a class="header-anchor" href="#发布语言文件"><span>发布语言文件</span></a></h4>
<p>如果你想将包的语言文件发布到应用程序的 <code v-pre>lang/vendor</code> 目录，可以使用服务提供者的 <code v-pre>publishes</code> 方法。<code v-pre>publishes</code> 方法接受一个包路径数组及其期望的发布位置。例如，要发布 <code v-pre>courier</code> 包的语言文件，可以执行以下操作：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导任何包服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">loadTranslationsFrom</span><span class="token punctuation">(</span><span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../lang'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'courier'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">publishes</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">        <span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../lang'</span> <span class="token operator">=></span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">langPath</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'vendor/courier'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>现在，当你的包用户执行 Laravel 的 <code v-pre>vendor:publish</code> Artisan 命令时，你包的语言文件将被发布到指定的发布位置。</p>
<h3 id="视图" tabindex="-1"><a class="header-anchor" href="#视图"><span>视图</span></a></h3>
<p>要向 Laravel 注册你包的 <a href="https://learnku.com/docs/laravel/11.x/viewsmd" target="_blank" rel="noopener noreferrer">视图</a>，你需要告知 Laravel 视图的位置。你可以使用服务提供者的 <code v-pre>loadViewsFrom</code> 方法来实现这一点。<code v-pre>loadViewsFrom</code> 方法接受两个参数：视图模板的路径和包的名称。例如，如果你的包名称是 <code v-pre>courier</code>，你将在服务提供者的 <code v-pre>boot</code> 方法中添加以下内容：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导任何包服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">loadViewsFrom</span><span class="token punctuation">(</span><span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../resources/views'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'courier'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>包视图使用 <code v-pre>package::view</code> 语法约定引用。因此，一旦你的视图路径在服务提供者中注册，你可以这样加载 <code v-pre>courier</code> 包的 <code v-pre>dashboard</code> 视图：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Route</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/dashboard'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token function">view</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'courier::dashboard'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="替换包视图" tabindex="-1"><a class="header-anchor" href="#替换包视图"><span>替换包视图</span></a></h4>
<p>当你使用 <code v-pre>loadViewsFrom</code> 方法时，Laravel 实际上会注册你的视图的两个位置：应用程序的 <code v-pre>resources/views/vendor</code> 目录和你指定的目录。例如，使用 <code v-pre>courier</code> 包为例，Laravel 首先会检查开发者是否已经在 <code v-pre>resources/views/vendor/courier</code> 目录中放置了视图的自定义版本。然后，如果视图尚未进行自定义，Laravel 将搜索你在调用 <code v-pre>loadViewsFrom</code> 时指定的包视图目录。这样，包的用户很容易自定义 / 替换你的包视图。</p>
<h4 id="发布视图" tabindex="-1"><a class="header-anchor" href="#发布视图"><span>发布视图</span></a></h4>
<p>如果你想要使视图可被发布到应用程序的 <code v-pre>resources/views/vendor</code> 目录，你可以使用服务提供者的 <code v-pre>publishes</code> 方法。<code v-pre>publishes</code> 方法接受一个包视图路径和其期望的发布位置的数组：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导任何包服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">loadViewsFrom</span><span class="token punctuation">(</span><span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../resources/views'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'courier'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">publishes</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">        <span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../resources/views'</span> <span class="token operator">=></span> <span class="token function">resource_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'views/vendor/courier'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>现在，当你的包用户运行 Laravel 的 <code v-pre>vendor:publish</code> Artisan 命令时，你的包的视图将被复制到指定的发布位置。</p>
<h3 id="视图组件" tabindex="-1"><a class="header-anchor" href="#视图组件"><span>视图组件</span></a></h3>
<p>如果你正在构建一个使用 Blade 组件的包，或者在非常规目录中放置组件，你将需要手动注册你的组件类和其 HTML 标签别名，以便 Laravel 知道在哪里找到组件。你通常应该在包的服务提供者的 <code v-pre>boot</code> 方法中注册你的组件：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Blade</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">VendorPackage<span class="token punctuation">\</span>View<span class="token punctuation">\</span>Components<span class="token punctuation">\</span>AlertComponent</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导包的服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token class-name static-context">Blade</span><span class="token operator">::</span><span class="token function">component</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'package-alert'</span><span class="token punctuation">,</span> <span class="token class-name static-context">AlertComponent</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>注册组件后，可以使用其标签别名进行渲染：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">&lt;x-package-alert/&gt;</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="自动加载包组件" tabindex="-1"><a class="header-anchor" href="#自动加载包组件"><span>自动加载包组件</span></a></h4>
<p>或者，你可以使用 <code v-pre>componentNamespace</code> 方法通过规范自动加载组件类。例如，一个 <code v-pre>Nightshade</code> 包可能有 <code v-pre>Calendar</code> 和 <code v-pre>ColorPicker</code> 组件，它们位于 <code v-pre>Nightshade\Views\Components</code> 命名空间中：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Blade</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导包的服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token class-name static-context">Blade</span><span class="token operator">::</span><span class="token function">componentNamespace</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Nightshade\\Views\\Components'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'nightshade'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>这将允许通过 <code v-pre>package-name::</code> 语法使用包组件的提供商命名空间：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">&lt;x-nightshade::calendar /&gt;</span>
<span class="line">&lt;x-nightshade::color-picker /&gt;</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><p>Blade 将自动检测与此组件链接的类，通过转换组件名称的大写驼峰命名。子目录也支持使用「.」表示法。</p>
<h4 id="匿名组件" tabindex="-1"><a class="header-anchor" href="#匿名组件"><span>匿名组件</span></a></h4>
<p>如果你的包包含匿名组件，必须将它们放在包的「视图」目录（如 <a href="#views"><code v-pre>loadViewsFrom</code> 方法</a> 所指定）的 <code v-pre>components</code> 目录中。然后，你可以通过在组件名称前加上包的视图命名空间来渲染它们：</p>
<div class="language-blade line-numbers-mode" data-highlighter="prismjs" data-ext="blade" data-title="blade"><pre v-pre class="language-blade"><code><span class="line">&lt;x-courier::alert /&gt;</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="「about」artisan-命令" tabindex="-1"><a class="header-anchor" href="#「about」artisan-命令"><span>「About」Artisan 命令</span></a></h3>
<p>Laravel 内置的 <code v-pre>about</code> Artisan 命令提供了应用程序环境和配置的概览。包可以通过 <code v-pre>AboutCommand</code> 类将额外信息推送到该命令的输出中。通常，这些信息可以从包服务提供者的 <code v-pre>boot</code> 方法中添加：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Foundation<span class="token punctuation">\</span>Console<span class="token punctuation">\</span>AboutCommand</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导任何应用程序服务。</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token class-name static-context">AboutCommand</span><span class="token operator">::</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'My Package'</span><span class="token punctuation">,</span> <span class="token keyword">fn</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'Version'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'1.0.0'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="命令" tabindex="-1"><a class="header-anchor" href="#命令"><span>命令</span></a></h2>
<p>要在 Laravel 中注册包的 Artisan 命令，可以使用 <code v-pre>commands</code> 方法。此方法期望一个命令类名数组。注册命令后，你可以使用 <a href="https://learnku.com/docs/laravel/11.x/artisanmd" target="_blank" rel="noopener noreferrer">Artisan CLI</a> 执行它们：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Courier<span class="token punctuation">\</span>Console<span class="token punctuation">\</span>Commands<span class="token punctuation">\</span>InstallCommand</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Courier<span class="token punctuation">\</span>Console<span class="token punctuation">\</span>Commands<span class="token punctuation">\</span>NetworkCommand</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导任何包服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">runningInConsole</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">commands</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">            <span class="token class-name static-context">InstallCommand</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token class-name static-context">NetworkCommand</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="公共资源" tabindex="-1"><a class="header-anchor" href="#公共资源"><span>公共资源</span></a></h2>
<p>你的包可能有如 JavaScript、CSS 和图像之类的前端资源。要将这些资源发布到应用程序的 <code v-pre>public</code> 目录，请使用服务提供者的 <code v-pre>publishes</code> 方法。在此示例中，我们还将添加一个 <code v-pre>public</code> 资源组标签，该标签可以用于轻松发布相关资源组：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导任何包服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">publishes</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">        <span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../public'</span> <span class="token operator">=></span> <span class="token function">public_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'vendor/courier'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'public'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>现在，当你的包用户运行 <code v-pre>vendor:publish</code> 命令时，你的资源将被复制到指定的发布位置。由于用户通常需要每次更新包时覆盖资源，你可以使用 <code v-pre>--force</code> 标志：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>public <span class="token parameter variable">--force</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="发布文件组" tabindex="-1"><a class="header-anchor" href="#发布文件组"><span>发布文件组</span></a></h2>
<p>你可能想要分别发布包资源和资源组。例如，你可能希望允许用户发布包的配置文件而不强迫发布包的资源。当从包的服务提供者调用 <code v-pre>publishes</code> 方法时，你可以通过「tagging」它们来实现这一点。例如，让我们在包服务提供者的 <code v-pre>boot</code> 方法中使用标签为 <code v-pre>courier</code> 包定义两个发布组（<code v-pre>courier-config</code> 和 <code v-pre>courier-migrations</code>）：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 引导任何包服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">publishes</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">        <span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../config/package.php'</span> <span class="token operator">=></span> <span class="token function">config_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'package.php'</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'courier-config'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">publishesMigrations</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">        <span class="token constant">__DIR__</span><span class="token operator">.</span><span class="token string single-quoted-string">'/../database/migrations/'</span> <span class="token operator">=></span> <span class="token function">database_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'migrations'</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'courier-migrations'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>现在，你的用户可以通过在执行 <code v-pre>vendor:publish</code> 命令时引用其标签，分别发布这些组：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>courier-config</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/11.x/packagesmd/16684" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/pa...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/11.x/packagesmd/16684" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/pa...</a></p>
</blockquote>
</div></template>


